package com.xmu.prcs.intercept;

import java.util.Map;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class AuthorizationInterceptor extends AbstractInterceptor{

	  
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		// 获取session   以及application  
		Map session = invocation.getInvocationContext().getSession();
		if(session.get("userId") == null){
			Map application = invocation.getInvocationContext().getApplication();
			//获取全局的权限列表   这个是前面服务器启动加载servlet时候放入application的  
			Map globalAuthorityMap = (Map)application.get("authorityMap");
			//获取请求的action的name  
			String actionName = invocation.getProxy().getActionName();
			System.out.println("interceptor : " + actionName);
			if(globalAuthorityMap.containsKey(actionName)){
				return Action.LOGIN;
			}
		}
		return invocation.invoke();
	}

}
